package com.cskaoyan.weixin.service;

import com.cskaoyan.bean.Category;
import com.cskaoyan.mapper.CategoryMapper;
import com.cskaoyan.weixin.bean.catalog.CatalogListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CatalogServiceImpl implements CatalogService {

    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public CatalogListVO queryCurrentCategory(Integer id) {
        Category currentCategory = categoryMapper.queryCatalogListById(id);
        List<Category> subCategoryList = categoryMapper.queryCatalogListByPid(currentCategory.getId());
        CatalogListVO catalogListVO = new CatalogListVO();
        catalogListVO.setCurrentCategory(currentCategory);
        catalogListVO.setCurrentSubCategory(subCategoryList);
        return catalogListVO;
    }

    @Override
    public CatalogListVO queryCatalogIndex() {
        List<Category> categoryList = categoryMapper.queryCatalogListByPid(0);
        CatalogListVO catalogListVO = queryCurrentCategory(categoryList.get(0).getId());
        catalogListVO.setCategoryList(categoryList);
        return catalogListVO;
    }
}
